package com.example.czxyproduct.web;

import com.example.czxyproduct.biz.AdvaBiz;
import com.example.czxyproduct.mapper.AdvaMapper;
import com.github.pagehelper.PageHelper;
import com.yc.czxy.bean.Adva;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("adva")
public class AdvaAction {

    @Resource
    AdvaMapper advaMapper;

    @Resource
    AdvaBiz advaBiz;

    @GetMapping("queryAdva")
    public List<Adva> queryAdva(){
        //查询要显示的广告
        PageHelper.startPage(1,3);
        List<Adva> alist = advaMapper.selectByObj();
        return alist;
    }
    @GetMapping("update")
    public void updateSchedule(){
        advaMapper.ScheduleUpdate();
    }
    @GetMapping("click")
    public ModelAndView click(int id){
        Adva adva = advaBiz.click(id);
        ModelAndView modelAndView
                = new ModelAndView("redirect:http://"+adva.getUrl());
        //响应重定向
        return modelAndView;
    }
}
